package com.mb.app.appused.greendao;

import java.util.List;

import com.mb.app.appused.greendao.database.DaoMaster;
import com.mb.app.appused.greendao.database.DaoSession;
import com.mb.app.appused.greendao.database.Histroy;
import com.mb.app.appused.greendao.database.HistroyDao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import de.greenrobot.dao.query.Query;

public class SimpleDataUtil {
	private SQLiteDatabase db;
	private DaoMaster daoMaster;
	private DaoSession daoSession;

	public void setupDatabase(Context context, String DataBaseName) {
		DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, DataBaseName, null);
		db = helper.getWritableDatabase();
		daoMaster = new DaoMaster(db);
		daoSession = daoMaster.newSession();
	}

	public List<Histroy> getList() {
		Query<Histroy> query = getHistroyDao().queryBuilder().build();
		List<Histroy> values = query.list();
		// List<BookItem> temp = new ArrayList<BookItem>();
		//
		// for (Histroy value : values) {
		// BookItem item = new BookItem();
		// item.name = book.getType();
		// item.cout = getNoteWithBook(book.getType());
		// temp.add(item);
		// }
		return values;
	}

	public void insert(Context context, String pack, String time, String type) {
		Histroy temp = getHistroyDao().queryBuilder().where(HistroyDao.Properties.Type.eq(pack),
				HistroyDao.Properties.Time.eq(time), HistroyDao.Properties.Type.eq(type)).build().unique();

		if (temp == null) {
			temp = new Histroy();
			temp.setType(type);
			temp.setPackageName(pack);
			temp.setTime(time);
			getHistroyDao().insert(temp);
		}
		
		// Simple value=new Simple();
		// value.setType(type);
		// value.setType(type);
		// getSimpleDao().insert(value);
		// getSimpleDao().update(value);
	}

	HistroyDao getHistroyDao() {
		return daoSession.getHistroyDao();
	}
}
